package com.itheima.admin.service.impl;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.admin.mapper.AdminMapper;
import com.itheima.admin.mapper.BlogMapper;
import com.itheima.admin.service.AdminService;
import com.itheima.xo.pojo.Admin;
import com.itheima.xo.pojo.Category;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :WuJunJie
 * packageName :com.itheima.admin.service.impl
 * fileName :AdminServiceImpl
 * creationTime :2022-11-04 16:44
 */
@Service
@Slf4j
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;


    @Override
    public Boolean add(Admin admin) {
        admin.setPassword(DigestUtil.md5Hex(admin.getPassword()));
        int insert = adminMapper.insert(admin);
        return insert>0;
    }

    @Override
    public Boolean delete(String id) {
        return null;
    }

    @Override
    public Boolean update(Admin admin) {
        return null;
    }

    @Override
    public List<Admin> findAll() {
        return null;
    }

    @Override
    public Admin findByEmail(String email) {
        LambdaQueryWrapper<Admin> lqw=new LambdaQueryWrapper<>();
        lqw.eq(Admin::getEmail,email);
        lqw.isNull(Admin::getDeleted);
        return adminMapper.selectOne(lqw);
    }
}
